import matplotlib.pyplot as plt
import numpy as np

# 定义小正方体的边长
edge_length = 20

# 定义小正方体的尺寸
width = height = depth = edge_length

# 创建一个立方体的3D网格
x = np.arange(0, width, 1)
y = np.arange(0, height, 1)
z = np.arange(0, depth, 1)
x, y, z = np.meshgrid(x, y, z)

# 创建图形和轴
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 绘制小正方体
for xi in range(x.shape[0]):
    for yi in range(y.shape[1]):
        for zi in range(z.shape[2]):
            # 每个小正方体的8个顶点
            xx, yy, zz = [xi, xi, xi+1, xi+1, xi, xi, xi+1, xi+1], \
                         [yi, yi+1, yi+1, yi, yi, yi+1, yi+1, yi], \
                         [zi, zi, zi, zi, zi+1, zi+1, zi+1, zi+1]
            ax.bar3d(xx, yy, zz, 1, 1, 1, color='b', alpha=0.5)

# 设置轴的标签
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')

# 设置轴的界限
ax.set_xlim([0, edge_length])
ax.set_ylim([0, edge_length])
ax.set_zlim([0, edge_length])

# 显示图形
plt.show()
plt.savefig('pe.png')